package com.qidian.mes.pro.service.impl;

import com.qidian.mes.pojo.Mat;
import com.qidian.mes.pojo.TechniqueMat;
import com.qidian.mes.pro.mapper.MatMapper;
import com.qidian.mes.pro.service.MatService;
import com.qidian.mes.util.dot.PagerDTO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author dqy
 * @Description
 * @Time 2024/4/24 10:03
 */
@Service
public class MatServiceImpl implements MatService {
    @Autowired
    private MatMapper matMapper;
    @Override
    public QdResult saveMat(TechniqueMat techniqueMat) {
        return QdResult.isSuccess(matMapper.insertMat(techniqueMat));
    }

    @Override
    public QdResult updateMat(TechniqueMat techniqueMat) {
        if (techniqueMat.getMatId()==null)
            return QdResult.error("没有对应的Id");
        return QdResult.isSuccess(matMapper.updateMat(techniqueMat));
    }

    @Override
    public QdResult deleteById(Long matId) {
        matMapper.deleteMat(matId);
        return QdResult.success();
    }

    @Override
    public QdResult deletes(Long[] matIds) {
        matMapper.deleteMats(matIds);
        return QdResult.success();
    }

    @Override
    public QdResult<PagerDTO<TechniqueMat>> queryPager(TechniqueMat techniqueMat, int start, int limit) {
        PagerDTO<TechniqueMat> pagerDTO = new PagerDTO<>();
        pagerDTO.setPage(start);
        pagerDTO.setLimit(limit);
        pagerDTO.setTotal(matMapper.selectCount(techniqueMat));
        List<TechniqueMat> techniques = matMapper.queryByPage(techniqueMat,(start-1)*limit,limit);
        pagerDTO.setData(techniques);
        return QdResult.success(pagerDTO);
    }

    @Override
    public QdResult queryById(Long matId) {
        return QdResult.success(matMapper.selectById(matId));
    }
}
